from django.contrib.auth.models import Permission, Group
from django.contrib.contenttypes.models import ContentType
from rest_framework.generics import ListAPIView, ListCreateAPIView
from rest_framework.viewsets import ModelViewSet

from apps.users.models import User
from meiduo_mall_admin.meiduo_admin.serializers import PermissionSerializer, PagNun, PermissionTypeSerializer, \
  PermissionGroupSerializer, PermissionAdminSerializer


#获取权限数据
class PermissionView(ModelViewSet):

  queryset = Permission.objects.all()
  serializer_class = PermissionSerializer
  pagination_class = PagNun

#获取权限列表
class PermissionTypeView(ListCreateAPIView):

  queryset = ContentType.objects.all()
  serializer_class = PermissionTypeSerializer


#获取组管理
class PermissionGroupView(ModelViewSet):

  queryset = Group.objects.all()
  serializer_class = PermissionGroupSerializer
  pagination_class = PagNun

class PermissionListView(ListAPIView):
  queryset = Permission.objects.all()
  serializer_class = PermissionSerializer


#---------管理员-----------
class PermissionAdminView(ModelViewSet):

  queryset = User.objects.filter(is_staff=True)
  serializer_class = PermissionAdminSerializer
  pagination_class = PagNun


class PermissionGroupListView(ListAPIView):
  queryset = Group.objects.all()
  serializer_class = PermissionGroupSerializer
